import type { PageList, ResponseStruct } from '#/global'
import { CourseCategoryVo } from './category';
import { CourseTaglVo } from './tag';

export interface CourseVo {
  id?: number;
  title?: string;
  introduce?: string;
  score_option?: { [key: string]: string };
  thumb?: string;
  is_publish?: number;
  tag_ids?: number[];
  category_ids?: number[];
  categorys?: CourseCategoryVo[],
  tags?: CourseTaglVo[]
}

export interface CourseSearchVo {
  title?: string;
  is_publish?: number;
  page_size?: number;
  with?: string[]
}

export function page(data: CourseSearchVo): Promise<ResponseStruct<PageList<CourseVo>>> {
  return useHttp().get('/admin/course', { params: data })
}

export function create(data: CourseVo): Promise<ResponseStruct<null>> {
  return useHttp().post('/admin/course', data)
}

export function save(id: number, data: CourseVo): Promise<ResponseStruct<null>> {
  return useHttp().put(`/admin/course/${id}`, data)
}

export function deleteByIds(ids: number[]): Promise<ResponseStruct<null>> {
  return useHttp().delete('/admin/course', { data: ids })
}

export function all(params = {}): Promise<ResponseStruct<CourseVo[]>> {
  return useHttp().get('/admin/course/all', { params })
}
